<?php
/* @var $this DefaultController */

$this->breadcrumbs=array(
	$this->module->id,
);

$url = CHtml::normalizeUrl(array('/marcar/entrenar/getphoto', 'format'=>'png'));
$boton = CHtml::button('Enviar foto', array('onclick'=>'take_snapshot();'));
?>

<div id="mensaje"></div>

<h1>Entrenar Reconocimiento Facial</h1>

<div id="my_camera" style="width:320px; height:240px; margin: 40px auto;"></div>

<!-- Configure a few settings and attach camera -->
<script language="JavaScript">
	Webcam.set({
		image_format: 'png',
		jpeg_quality: 90
	});
	Webcam.attach( '#my_camera' );
	var url = <?php echo CJSON::encode($url);?>;
	var answerTimeout;
</script>

<div align="center" id="boton"><?php echo $boton; ?></div>

<script language="JavaScript">
	function take_snapshot() {
		// take snapshot and get image data
		var data_uri = Webcam.snap();
		Webcam.upload(data_uri, url, get_answer);
	}
	function set_answer (message) {
		var msg = $('#mensaje');
		clearTimeout(answerTimeout);
		msg.hide();
		msg.html(message);
		msg.fadeIn();
		answerTimeout = setTimeout(function() {msg.fadeOut();}, 3000);
	}
	function get_answer(code,text) {
		set_answer(text);
	}
</script>